package com.example.demo.mapper;

import com.example.demo.entity.ArticleRemarks;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.entity.DTO.ArticleRemarksDTO;
import com.example.demo.entity.VO.ArticleRemarksVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Mr.we
 * @since 2024-06-04
 */
@Mapper
public interface ArticleRemarksMapper extends BaseMapper<ArticleRemarks> {
    //用户写评论
    @Insert("INSERT INTO article_remarks (user_id, article_id, remarks, create_time) " +
            "VALUES (#{userId}, #{articleId}, #{remarks}, NOW())")
    int addRemarks(ArticleRemarks articleRemarks);

    // 以帖子ID查询评论
    @Select("SELECT * FROM article_remarks WHERE article_id = #{articleId}")
    List<ArticleRemarks> selectRemarksByArticleId(Integer articleId);
    //精准查询评论
    @Select("SELECT * FROM article_remarks WHERE article_id = #{articleId} AND user_id = #{userId} AND remarks_id =#{remarksId}")
    List<ArticleRemarks> selectRemarksByThreeId(ArticleRemarks articleRemarks);

    //查询所有评论
    @Select("SELECT * FROM article_remarks where flag = 1")
    List<ArticleRemarksDTO> selectAllRemarks();

    //修改评论
    @Update("UPDATE article_remarks SET remarks = #{remarks}, update_time = NOW() " +
            "WHERE user_id = #{userId} AND article_id = #{articleId} AND remarks_id =#{remarksId}")
    int updateRemarks(ArticleRemarks articleRemarks);
    //删除评论
    @Delete("DELETE FROM article_remarks WHERE user_id = #{userId} " +
            "AND article_id =  #{articleId} AND remarks_id =#{remarksId}")
    int deleteRemarks(ArticleRemarks articleRemarks);

    //通过userId查询评论
    @Select("SELECT * FROM article_remarks WHERE user_id = #{userId}")
    List<ArticleRemarksDTO> selectRemarksByUserId(Integer userId);

}
